﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;


namespace IHISCETeim.BLL
{
    public class JSDWFFlowConfigController
    {
        public static int Add(JSDWFFlowConfigInfo obj)
        {
            return JSDWFFlowConfigDAL.Add(obj);
        }
        public static bool Delete(int FlowID, int AdtlvlID)
        {
            return JSDWFFlowConfigDAL.Delete(FlowID, AdtlvlID);
        }
        public static List<JSDWFFlowConfigInfo> GetAll(int AdtlvlID)
        {
            return CBO.FillCollection<JSDWFFlowConfigInfo>(JSDWFFlowConfigDAL.GetAll(AdtlvlID));
        }

        public static DataTable GetAllToDataTable(int AdtlvlID)
        {
            return JSDWFFlowConfigDAL.GetAllToDataTable(AdtlvlID);
        }
        /// <summary>
        /// 获取节点信息
        /// </summary>
        /// <param name="FlowId"></param>
        /// <returns></returns>
        public static JSDWFFlowConfigInfo GetByFlowId(int FlowId, int AdtlvlID)
        {
            return CBO.FillObject<JSDWFFlowConfigInfo>(JSDWFFlowConfigDAL.GetByID(FlowId, AdtlvlID));
        }
        /// <summary>
        /// 获取下一个流程 节点信息,
        /// 如果已达到最高节点，则返回空 null
        /// </summary>
        /// <param name="nowFlowId"></param>
        /// <returns></returns>
        public static JSDWFFlowConfigInfo GetNextFlow(int nowFlowId, int AdtlvlID)
        {
            try
            {
               // JSDWFFlowConfigInfo obj = GetByFlowId(nowFlowId,AdtlvlID);

                List<JSDWFFlowConfigInfo> list = GetAll(AdtlvlID).Where(e => e.State == true).ToList();
                JSDWFFlowConfigInfo info = list.OrderBy(ee => ee.FlowID).First(ee => ee.FlowID > nowFlowId);
                return info;
            }
            catch
            {
                return null;
            }
        }

        public static bool Update(JSDWFFlowConfigInfo obj)
        {
            return JSDWFFlowConfigDAL.Update(obj);
        }

    }
}
